// Explorer 相关样式统一管理
// 包含文件浏览器的所有组件样式

// 变量定义
$primary-color: #409eff;
$border-color: #e4e7ed;
$hover-bg: #f0f9ff;
$selected-bg: #e6f3ff;
$selected-border: #409eff;
$selected-shadow: rgba(64, 158, 255, 0.25);
$selected-highlight: #409eff;
$sidebar-bg: #f5f5f5;
$sidebar-width: 240px;
$sidebar-width-mobile: 200px;

// Mixin for user-select
@mixin user-select($value) {
  -webkit-user-select: $value;
  -moz-user-select: $value;
  -ms-user-select: $value;
  user-select: $value;
}

// 文件浏览器主容器
.file-explorer {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #fafafa;
}

// 统一工具栏样式
.explorer-toolbar {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: white;
  border-bottom: 1px solid $border-color;
  gap: 12px;

  &__left {
    display: flex;
    gap: 8px;
    align-items: center;
  }

  &__center {
    flex: 1;
    padding: 0 16px;

    .breadcrumb-item {
      cursor: pointer;
      @include user-select(none);

      &:hover {
        color: $primary-color;
      }
    }
  }

  &__right {
    display: flex;
    gap: 8px;
    align-items: center;
  }
}

// 主要内容区域
.explorer-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

// 侧边栏样式
.sidebar {
  width: $sidebar-width;
  background: $sidebar-bg;
  border-right: 1px solid $border-color;
  overflow-y: auto;

  .sidebar-section {
    margin-bottom: 16px;

    .section-title {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 8px 12px;
      font-weight: 500;
      color: #606266;
      font-size: 14px;
      @include user-select(text);
    }

    .sidebar-item {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 6px 12px;
      cursor: pointer;
      transition: background-color 0.2s;
      font-size: 13px;
      white-space: nowrap;
      overflow: hidden;

      &:hover {
        background: #e6f3ff;
      }

      &.active {
        background: $primary-color;
        color: white;

        .drive-info {
          color: rgba(255, 255, 255, 0.8); // 选中时保持良好的文字对比度
        }
      }

      .sidebar-text {
        flex: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        @include user-select(text);
      }

      .drive-info {
        margin-left: auto;
        font-size: 11px;
        color: #909399;
        flex-shrink: 0;
        @include user-select(text);
      }
    }
  }
}

// 主内容区域
.main-content {
  flex: 1;
  background: white;
  overflow: auto; // 恢复默认值
  padding: 12px;

  // 空文件夹提示
  .empty-folder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 400px;
    color: #909399;

    .empty-icon {
      margin-bottom: 20px;
      opacity: 0.6;
      color: #c0c4cc;
      @include user-select(none);
    }

    .empty-title {
      font-size: 18px;
      font-weight: 500;
      margin: 0 0 8px 0;
      color: #606266;
      @include user-select(text);
    }

    .empty-subtitle {
      font-size: 14px;
      margin: 0;
      color: #909399;
      text-align: center;
      max-width: 300px;
      line-height: 1.5;
      @include user-select(text);
    }
  }

  // 文件容器
  .file-container {
    width: 100%;
  }

  // 文件列表（列表模式）
  .file-list {
    display: flex;
    flex-direction: column;
    // 移除边框避免与文件项outline冲突导致抖动
    border: none;
    border-radius: 4px;
    background: white;
    overflow: hidden;
  }

  // 文件网格（网格模式）
  .file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
  }
}

// 右键菜单样式
.context-menu {
  position: fixed;
  background: white;
  border: 1px solid $border-color;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 4px 0;
  min-width: 160px;
  z-index: 1000;

  .menu-item {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    transition: background-color 0.2s;

    &:hover {
      background: $hover-bg;
    }

    &.disabled {
      color: #c0c4cc;
      cursor: not-allowed;

      &:hover {
        background: transparent;
      }
    }

    .menu-icon {
      margin-right: 8px;
      width: 16px;
    }

    .menu-text {
      flex: 1;
    }

    .menu-shortcut {
      margin-left: 12px;
      font-size: 11px;
      color: #909399;
    }
  }

  .menu-divider {
    height: 1px;
    background: #f0f0f0;
    margin: 4px 0;
  }
}

// 响应式设计
@media (max-width: 768px) {
  .sidebar {
    width: $sidebar-width-mobile;
  }

  .explorer-toolbar {
    padding: 6px 8px;
    gap: 8px;

    &__center {
      padding: 0 8px;
    }
  }

  .file-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }
}

// 平板设备适配
@media (max-width: 1024px) and (min-width: 769px) {
  .file-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  }
}

// 动画和过渡效果
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes selectPulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.02);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes selectGlow {
  0% {
    border-color: $selected-border;
  }
  50% {
    border-color: rgba(64, 158, 255, 0.8);
  }
  100% {
    border-color: $selected-border;
  }
}

.context-menu {
  animation: fadeIn 0.2s ease-out;
}

// 选中动画 - 已禁用以避免闪烁
// .file-list-item.selected {
//   animation: selectPulse 2s ease-in-out infinite;
// }

// .file-item.selected {
//   animation: selectGlow 2s ease-in-out infinite;
// }

// 滚动条样式
.sidebar::-webkit-scrollbar,
.main-content::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-track,
.main-content::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb,
.main-content::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;

  &:hover {
    background: #9ca3af;
  }
}

// 选择文本时的样式
::selection {
  background: rgba(64, 158, 255, 0.3);
}

// 拖拽时的样式优化 - 彻底移除黑边框
*[draggable="true"] {
  -webkit-user-drag: element;
}

// 移除拖拽时的默认黑边框 - 使用最高优先级
*,
*:hover,
*:focus,
*:active,
*:focus-visible {
  outline: none !important;
}

// 特别针对文件项的样式重置
.file-item,
.file-list-item,
.file-icon {
  outline: none !important;
  border: none !important;
  -webkit-tap-highlight-color: transparent !important;

  &,
  &:hover,
  &:focus,
  &:active {
    outline: none !important;
    border: none !important;
  }
}

// 拖拽元素的样式
.dragging {
  opacity: 0.5;
  transform: rotate(2deg);
}
